/**
 * 
 */
package cvcg.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.ForeignKey;

/**
 * @author jaracje
 *
 */
@Entity
@Table(name="SCORE")
@SuppressWarnings("serial")
public class Score implements Serializable
{
	@Id @GeneratedValue
	@Column(name="SCORE_P")
	private Long id;
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="GAME_F",unique=true)
	@ForeignKey(name = "CTR_SCORE_R_GAME")	
	private Game game;
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="PLAYER_F")
	@ForeignKey(name = "CTR_SCORE_R_PLAYER")	
	private Player player;
	private Integer points;
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the game
	 */
	public Game getGame() {
		return game;
	}
	/**
	 * @param game the game to set
	 */
	public void setGame(Game game) {
		this.game = game;
	}
	/**
	 * @return the player
	 */
	public Player getPlayer() {
		return player;
	}
	/**
	 * @param player the player to set
	 */
	public void setPlayer(Player player) {
		this.player = player;
	}
	/**
	 * @return the points
	 */
	public Integer getPoints() {
		return points;
	}
	/**
	 * @param points the points to set
	 */
	public void setPoints(Integer points) {
		this.points = points;
	}		
	
	@Transient
	public String getGameName() 
	{
		String gameName = null;
		if(game!=null) 
		{
			return game.getName();
		}
		return gameName;
	}
	
	@Transient
	public String getPlayerName() 
	{
		String playerName = null;
		if(player!=null) 
		{
			return player.getName();
		}
		return playerName;
	}
	
	@Transient
	public Long getGameId() 
	{
		Long gameId=null;
		if (game!=null) 
		{
			gameId = game.getId();			
		}
		return gameId;
	}
	
	@Transient
	public Long getPlayerId() 
	{
		Long playerId=null;
		if (player!=null) 
		{
			playerId = player.getId();			
		}
		return playerId;
	}

}
